//
//  FKConfirmOrderCell.m
//  HappyTest
//
//  Created by Macbook Pro on 2019/2/19.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKConfirmOrderCell.h"

@interface FKConfirmOrderCell ()

/** 商品图片*/
@property (nonatomic, weak) UIImageView *picView;
/** 商品名称*/
@property (nonatomic, weak) UILabel *nameLabel;
/** 电子码商品描述 */
@property (nonatomic, weak) UILabel *elecCodeLabel;
/** 商品规格*/
@property (nonatomic, weak) UILabel *specLabel;
/** 商品价格*/
@property (nonatomic, weak) UILabel *priceLabel;
/** 商品数量*/
@property (nonatomic, weak) UILabel *numLabel;
@property (nonatomic, weak) UIButton *noDiscountBtn;

@end

@implementation FKConfirmOrderCell

- (void)setupSubviews
{
    [super setupSubviews];
//    self.contentView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIImageView *picView = [[UIImageView alloc] init];
    [self.contentView addSubview:picView];
    self.picView = picView;
    
    UILabel *nameLabel = [UILabel fk_labelWithFont:fk_adjustFont(14) textColor:fkColor333333];
    [self.contentView addSubview:nameLabel];
    self.nameLabel = nameLabel;
    nameLabel.numberOfLines = 2;
    
    UILabel *elecCodeLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkMainColor text:@"电子码商品不支持退款哦!"];
    [self.contentView addSubview:elecCodeLabel];
    self.elecCodeLabel = elecCodeLabel;
    
    UILabel *specLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor999999];
    [self.contentView addSubview:specLabel];
    self.specLabel = specLabel;
    specLabel.numberOfLines = 2;
    
    UILabel *priceLabel = [UILabel fk_labelWithFont:fk_adjustFont(14) textColor:fkPriceRed];
    [self.contentView addSubview:priceLabel];
    self.priceLabel = priceLabel;
    
    UILabel *numLabel = [UILabel fk_labelWithFont:fk_adjustFont(11) textColor:fkColor333333];
    [self.contentView addSubview:numLabel];
    self.numLabel = numLabel;
    
    UIButton *noDiscountBtn = [UIButton fk_btnWithTarget:self action:@selector(noDiscountBtnClicked) font:fk_adjustFont(12) normalTitle:@"不支持优惠" normalTitleColor:fkColor999999 selectedTitle:nil selectedTitleColor:nil normalImg:[UIImage imageNamed:@"no_discount"] selectedImg:nil bgImg:nil selectedBgImg:nil];
    [self.contentView addSubview:noDiscountBtn];
    self.noDiscountBtn = noDiscountBtn;
    noDiscountBtn.hidden = true;
    
    UIView *separator = [[UIView alloc] init];
    [self.contentView addSubview:separator];
    separator.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    [picView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(fk_adjustW(100));
        make.left.offset(12);
        make.centerY.offset(0);
    }];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(fk_adjustW(10));
        make.left.equalTo(picView.mas_right).offset(12);
        make.right.offset(-12);
    }];
    [specLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(picView);
        make.top.equalTo(nameLabel.mas_bottom).offset(fk_adjustW(6));
        make.left.right.equalTo(nameLabel);
    }];
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.offset(fk_adjustW(-10));
        make.left.equalTo(nameLabel);
    }];
    [elecCodeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(specLabel);
        make.bottom.equalTo(priceLabel.mas_top).offset(fk_adjustW(-6));
    }];
    [numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(nameLabel);
        make.centerY.equalTo(priceLabel);
    }];
    [noDiscountBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(numLabel);
        make.bottom.equalTo(numLabel.mas_top).offset(-6);
    }];
    [separator mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.offset(0);
        make.height.offset(0.8);
    }];
}

- (void)noDiscountBtnClicked
{
    [SVProgressHUD showInfoWithStatus:@"特价商品无优惠"];
}

- (void)setData:(id)data
{
    [super setData:data];
    
    [self.picView sd_setImageWithURL:[NSURL URLWithString:data[@"goods_image"]] placeholderImage:kPlaceholder_1x1];
    self.nameLabel.text = data[@"goods_title"];
    self.specLabel.text = data[@"option_title"];
    self.elecCodeLabel.hidden = ![data[@"is_elec_code"] boolValue];
    NSMutableAttributedString *priceAttr1 = [@"￥" fk_addAttr:fkMainColor font:fk_adjustFont(13)];
    NSMutableAttributedString *priceAttr2 = [data[@"goods_price"] fk_addAttr:fkMainColor font:fk_adjustFont(18)];
    NSMutableAttributedString *priceAttr3 = [fkFORMAT(@" 省￥%@", data[@"share_commission"]) fk_addAttr:fkMainColor font:fk_adjustFont(12)];
    [priceAttr1 appendAttributedString:priceAttr2];
    if ([FKCacheTool isMember]) [priceAttr1 appendAttributedString:priceAttr3];
    self.priceLabel.attributedText = priceAttr1;
    self.numLabel.text = fkFORMAT(@"x%@", data[@"goods_num"]);
    
    self.noDiscountBtn.hidden = [data[@"is_special_price"] isEqualToString:@"0"];
    
    
//    // 测试脏数据
//    self.nameLabel.text = @"测试\n测试";
//    self.specLabel.text = @"这是商品规格";
//    self.noDiscountBtn.hidden = false;
//    self.elecCodeLabel.hidden = false;
}

@end
